import _ from "lodash";
import { Tools } from "../../framework/utils/Tools";
import { ConfigObjects } from "./ConfigObjects";

export class ConfigManager {

    private static _instance: ConfigManager;

    public static get inst(): ConfigManager {
        if (!this._instance) {
            this._instance = new ConfigManager();
        }
        return this._instance;
    }



    public async load(): Promise<void> {

        const config_index: string = __dirname + "/../../../bin/config.json";

        const data: string = await Tools.readFile(config_index);

        const sheetNames: string[] = JSON.parse(data);


        _.each(sheetNames, async sheetname => {
            const file_path: string = __dirname + `/../../../bin/bin_Cfg${sheetname}.json`

            const data: any = JSON.parse(await Tools.readFile(file_path));

            _.each(data,tb=>{
                ConfigObjects[sheetname][tb.id] = tb;
            });
            
        });
    }
}